<template>
    <view class="custom-tabbar">
        <view class="tab-item" @click="navigateToFn(1)" id="1">
            <image class="image" src="../../static/1Home-two.png" v-show="currentTab != '/pages/home/index'"></image>
            <image class="image" src="../../static/Home-two.png" v-show="currentTab == '/pages/home/index'"></image>
            <text class="tab-text" :class="currentTab == 1 ? 'active' : ''">首页</text>
        </view>
        <view class="tab-item" @click="navigateToFn(2)" id="2">
            <!-- currentTab.value.split('?')[0] || -->
            <image class="image" src="../../static/Group 1142813305.png" v-show="currentTab != '/pages/index/index'"></image>
            <image class="image" src="../../static/1Group 1142813305.png" v-show="currentTab == '/pages/index/index'"></image>
            <text class="tab-text" :class="currentTab == 2 ? 'active' : ''">订单</text>
        </view>
        <view class="tab-item" @click="navigateToFn(3)" id="3">
            <!-- currentTab.value.split('?')[0] || -->
            <image class="image" src="../../static/Home-two1h1.png" v-show="currentTab != '/pages/loginView/loginView'"></image>
            <image class="image" src="../../static/Home-twoqh.png" v-show="currentTab == '/pages/loginView/loginView'"></image>
            <text class="tab-text" :class="currentTab == 3 ? 'active' : ''">切换账号</text>
        </view>
    </view>
</template>

<script setup>
import { ref, onBeforeMount } from 'vue';
import { onLoad, onShow } from '@dcloudio/uni-app';
onBeforeMount(() => {});
const props = defineProps({
    currentTab: {
        type: String,
        default: '/pages/home/index'
    }
});
const currentTab = ref(); // 当前选中的 tab
const fn = () => {
    const res = getCurrentPages();
    currentTab.value = res[res.length - 1].$page.fullPath || props.currentTab;
    currentTab.value = currentTab.value.split('?')[0];
};
onShow(() => {
    fn();
});
function getTmplID() {
    uni.requestSubscribeMessage({
        tmplIds: ['6YQ3oH3AHXtkDUDES_2Jf0psD9VUe7PEs37wA0K8n0w'],
        success(res) {
            // console.log(res);
            // uni.showToast({
            //     title: '订阅成功'
            // });
        },
        fail() {
            // uni.showToast({
            //     title: '订阅失败',
            //     icon: 'none'
            // });
        }
    });
}
function navigateToFn(num) {
    if (num == 1) {
        uni.redirectTo({
            url: '/pages/home/index'
        });
        uni.getSetting({
            withSubscriptions: true,
            success(res) {
                // console.log(res);
                if (res.subscriptionsSetting && res.subscriptionsSetting.itemSettings) {
                    let isSubscribed = res.subscriptionsSetting.itemSettings['6YQ3oH3AHXtkDUDES_2Jf0psD9VUe7PEs37wA0K8n0w'] === 'accept';
                    if (isSubscribed) {
                        // 用户已订阅
                        return;
                    } else {
                        // 用户未订阅或拒绝订阅
                    }
                    return;
                } else {
                }
            }
        });
        getTmplID();
    } else if (num == 2) {
        uni.redirectTo({
            url: '/pages/index/index'
        });
    } else if (num == 3) {
        uni.redirectTo({
            url: '/pages/loginView/loginView?type=1'
        });
    }
}
</script>

<style scoped lang="scss">
.custom-tabbar {
    display: flex;
    justify-content: space-around;
    align-items: center;
    height: 135rpx;
    font-size: 28rpx;
    background-color: #fff;
    border-top: #f1fff1 solid 1rpx;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 9999;
    .tab-item {
        flex: 1;
        text-align: center;
        /* 其他样式 */
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        .image {
            width: 50rpx;
            height: 50rpx;
        }
    }

    .active {
        /* 选中时的样式 */
        color: #3ab0ff !important;
    }
}
</style>
